
var domain="";
/**
 * 
 * @file_name gaopeng.script.js
 * @Description: TODO
 * @author wenwei.wan@gaopeng.com
 * @date 2011-9-7 下午3:09:20 
 * @param url  js的url
 * @param call  加载完毕执行的动作
 * @returns {loadScript}
 */
function loadScript(url,call){
	if(loadScript.prototype.jsMap){
		var jm = loadScript.prototype.jsMap.get(url);
		if(jm==url){
			if (call) call();
			return;//避免重复加载
		}
		loadScript.prototype.jsMap.put(url,url);
	}
	var doc = document;
	var	el = doc.createElement('script');
	var	head = doc.getElementsByTagName('head')[0];
	if (call) {
		if (doc.all) {
			el.onreadystatechange = function(){
				if (el.readyState == 'loaded' || el.readyState == 'complete') call();
			}
		}
		else el.onload = call;
	}
	el.setAttribute('type','text/javascript');
	el.src = url;
	head.appendChild(el);
}

/**
 * 
 * @file_name gaopeng.script-1.1.js
 * @Description: TODO 按需加载js，异步方式执行
 * @author wenwei.wan@gaopeng.com
 * @date 2011-9-8 上午10:39:49 
 * @param arr js路径数组
 */
function onDemandSyncLoad(arr){
	var objHead = document.getElementsByTagName("head");
	for(i=0,j=arr.length;i<j;i++){
		var bAddJs = true;
		var urlPrefix = arr[i].isMacthHttp();
		var url = (urlPrefix==false?domain:"")+arr[i];
		var jm = loadScript.prototype.jsMap.get(url);
		if(jm==url) continue;
		else loadScript.prototype.jsMap.put(url,url);
		if(bAddJs){//不存在添加Js
			var newScript =  document.createElement("script");
			newScript.src = url;
			newScript.type = "text/javascript";
			objHead[0].appendChild(newScript);
		}
	}
}

/**
 * 
 * @file_name gaopeng.script-1.1.js
 * @Description: TODO 按需加载js，同步方式执行
 * @author wenwei.wan@gaopeng.com
 * @date 2011-9-8 上午10:39:49 
 * @param arr js路径数组
 */
function onDemandAsyncLoad(arr,call){
	var loadingScriptFlag = 0;
	var syncSyncSize = arr.length;
	var urlPrefix = arr[loadingScriptFlag].isMacthHttp();
	var url = (urlPrefix==false?domain:"")+arr[loadingScriptFlag];
	loadScript(url,function (){
		loadingScriptFlag++;
		if(loadingScriptFlag<syncSyncSize){
			urlPrefix = arr[loadingScriptFlag].isMacthHttp();
			url = (urlPrefix==false?domain:"")+arr[loadingScriptFlag];
			loadScript(url,arguments.callee);
		} else {
			call();
		}
	});
}


/**
 * 
 * @file_name commons-0.1.gaopeng.js
 * @Description: TODO 解析xml 返回xml的对象
 * @author wenwei.wan@gaopeng.com
 * @date 2011-9-13 下午4:38:24 
 * @param string xml字符串
 * @returns dom对象
 */
function fnDomParser (string){
	if(!window.DOMParser){
		var progIDs = new Array("Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","MSXML2.DOMDocument","MSXML.DOMDocument");
		for(var i = 0;i<progIDs.length;i++){
			try{
				var obj = new ActiveXObject(progIDs[i]);
				obj.async = false;
				obj.setProperty("SelectionLanguage", "XPath");
				obj.loadXML(string);
				return obj;
			}catch(ex){
				
			}
		}
	}else{
		var parser = new DOMParser();
		return parser.parseFromString(string, "text/xml");
	}
}

/**
 * 
 * @file_name gaopeng.script-1.2.js
 * @Description: TODO  对相对路径跟绝对路径的支持
 * @author wenwei.wan@gaopeng.com
 * @date 2011-9-19 下午2:36:23 
 * @returns
 */
String.prototype.isMacthHttp = function (){
	var regExp = /^http(s)?:\/\//;
	return regExp.test(this);
};

Array.prototype.checkArrayRepeatRecord = function(id){
	var flag  = 0;
	for(var i=0;i<this.length;i++){
        if(this[i]==id) flag++;
    }
    return flag;
};